/*
 * Copyright (C) 2008-2010 TrinityCore <http://www.trinitycore.org/>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#include "ScriptPCH.h"
#include "ulduar.h"

#define SPELL_FLAME_JETS            62680
#define SPELL_SCORCH                62546
#define SPELL_SLAG_POT              62717

enum Yells
{
    SAY_AGGRO                                   = -1603220,
    SAY_SLAY_1                                  = -1603221,
    SAY_SLAY_2                                  = -1603222,
    SAY_DEATH                                   = -1603223,
    SAY_SUMMON                                  = -1603224,
    SAY_SLAG_POT                                = -1603225,
    SAY_SCORCH_1                                = -1603226,
    SAY_SCORCH_2                                = -1603227,
    SAY_BERSERK                                 = -1603228,
};

enum
{
    ACHIEV_TIMED_START_EVENT                      = 20951,
};

class boss_ignis : public CreatureScript
{
public:
    boss_ignis() : CreatureScript("boss_ignis") { }

    CreatureAI* GetAI(Creature* pCreature) const
    {
        return new boss_ignis_AI (pCreature);
    }

    struct boss_ignis_AI : public BossAI
    {
        boss_ignis_AI(Creature *pCreature) : BossAI(pCreature, TYPE_IGNIS) {}

        uint32 uiFlameJetsTimer;
        uint32 uiScorchTimer;
        uint32 uiSlagPotTimer;

        void Reset()
        {
            _Reset();
            uiFlameJetsTimer = 32000;
            uiScorchTimer = 100;
            uiSlagPotTimer = 100;

            if (instance)
                instance->DoStopTimedAchievement(ACHIEVEMENT_TIMED_TYPE_EVENT, ACHIEV_TIMED_START_EVENT);
        }

        void EnterCombat(Unit* /*who*/)
        {
            DoScriptText(SAY_AGGRO,me);
            _EnterCombat();

            if (instance)
                instance->DoStartTimedAchievement(ACHIEVEMENT_TIMED_TYPE_EVENT, ACHIEV_TIMED_START_EVENT);
        }

        void KilledUnit(Unit* /*victim*/)
        {
            DoScriptText(RAND(SAY_SLAY_1,SAY_SLAY_2), me);
        }

        void JustDied(Unit * /*victim*/)
        {
            DoScriptText(SAY_DEATH, me);
            _JustDied();
        }

        void MoveInLineOfSight(Unit* /*who*/) {}

        void UpdateAI(const uint32 diff)
        {
            if (!UpdateVictim())
                return;

            if (me->GetPositionY() < 150 || me->GetPositionX() < 450) // Not Blizzlike, anti-exploit to prevent players from pulling bosses to vehicles.
            {
                me->RemoveAllAuras();
                me->DeleteThreatList();
                me->CombatStop(false);
                me->GetMotionMaster()->MoveTargetedHome();
            }

            if (uiFlameJetsTimer <= diff)
            {
                DoCast(SPELL_FLAME_JETS);
                uiFlameJetsTimer = 25000;
            } else uiFlameJetsTimer -= diff;

            if (uiScorchTimer <= diff)
            {
                DoScriptText(RAND(SAY_SCORCH_1,SAY_SCORCH_2), me);
                DoCast(SPELL_SCORCH);
                uiScorchTimer = 20000;
            } else uiScorchTimer -= diff;

            if (uiSlagPotTimer <= diff)
            {
                if (Unit *pTarget = SelectTarget(SELECT_TARGET_RANDOM, 0, 100, true))
                {
                    DoScriptText(SAY_SLAG_POT, me);
                    DoCast(pTarget, SPELL_SLAG_POT);
                }
                uiSlagPotTimer = 30000;
            } else uiSlagPotTimer -= diff;

            DoMeleeAttackIfReady();
        }
    };

};
void AddSC_boss_ignis()
{
    new boss_ignis();
}
